<?php 
# 文件名称:database.view.php
# MetInfo在线反馈系统 
# Copyright (C) 长沙米拓信息技术有限公司 (http://www.metinfo.cn). All rights reserved.
class databaseView extends C_view
{
	function databaseView()
	{
		parent::C_view();
	}
	//加载模板
	function display($tpl)
	{		
		$SYS = &get_instance();
		$SYS->html->script('core.js');
		$this->assignRef('message', $SYS->loader->getMessageQueue());
		$class = $SYS->request->getVar('option', '', 'get');
		$class = $class==''?$SYS->request->getvar('option') : $class;
		$js_content="markRows();";
		$SYS->doc->addScriptDeclaration($js_content);
		switch($class)
		{			
			case 'restore':
							$js_content = "							
							initTableWidget('sortTable',Array(false,false,false,false,'S',false));
							var initSort = document.getElementById('defaultSort');
							image1='".$this->imagePath."sort_desc.png';
							image2='".$this->imagePath."sort_asc.png';
							sortTable(initSort);
							";
							$SYS->doc->addScriptDeclaration($js_content);
							$this->getRestore($tpl);break;
			default:
							$this->assignRef( 'title', C_text::_('database backup'));
							$js_content = "$('toggle').checked=true;checkAll(".count($this->get('Items')).");
							";
							$SYS->doc->addScriptDeclaration($js_content);
							$this->assignRef( 'items', $this->get('Items'));
							$this->assignRef( 'records', $this->get('Records'));
							parent::display('backup');
		}
	}
	//还原模板
	function getRestore($tpl = null)
	{		
		switch($tpl)
		{			
			default:							
							$this->assignRef( 'title', C_text::_('database restore'));							
							$this->assignRef('items', $this->getFileLists(PATH_BACKUP));
							parent::display('restore');
							break;
		}
	}
	//数据库备份文件
	function getFileLists($path)
	{
		//目录	
		$fso    =   @opendir($path);
		$result = 	array();
		$SYS =&get_instance();
		C_loader::helper('date');
		if($fso)
		{
			while($file=readdir($fso))
			{
				if($file!='.' && $file!='..')
				{			
					$filepath=$path.DS.$file;
					//处理文件
					if(is_file($filepath)) 
					{		
						if(preg_match("/([a-z0-9_]+_[0-9]{8}_[0-9a-z]{4})+\.sql/i",basename($filepath),$num))
						{
							$tmp = new stdClass();
							$tmp->backuptime = standard_date(filemtime($filepath));
							$tmp->filesize = intval(filesize($filepath)/1024);
							$tmp->filename = $file;
							$tmp->name = $num[1];
							$result[] = $tmp;
						}else @unlink($filepath);
					}
				}				
			}
		}
		@closedir($fso);
		return $result;
	}
	
}
# 本程序是一个开源系统,使用时请你仔细阅读使用协议,商业用途请自觉购买商业授权.
# Copyright (C) 长沙米拓信息技术有限公司 (http://www.metinfo.cn). All rights reserved.
?>